package com.yide.myworld.api_result;

import com.alibaba.fastjson2.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
public class NettyResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private Integer gameType;

    private String message;

    private Object data;

    public static TextWebSocketFrame fail(Integer gameType, String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(-1, gameType, message, null)));
    }

    public static TextWebSocketFrame fail(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(-1, null, message, null)));
    }

    public static TextWebSocketFrame authFail(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(-2, null, message, null)));
    }

    public static TextWebSocketFrame success(Integer gameType, String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(200, gameType, message, null)));
    }

    public static TextWebSocketFrame success(Integer code, Integer gameType, String message) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(code, gameType, message, null)));
    }

    public static TextWebSocketFrame success(Integer code, Integer gameType, Object data) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(code, gameType, null, data)));
    }

    public static TextWebSocketFrame success(Integer code, Object data) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(code, null, null, data)));
    }

    public static TextWebSocketFrame success(Integer code, Integer gameType, String message, Object data) {
        return new TextWebSocketFrame(JSON.toJSONString(new NettyResult(code, gameType, message, data)));
    }

}
